package com.touna.annotation.validator;

import com.touna.annotation.Idcard;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * author: xl
 * time: 2018/6/15 16:27
 * description: 校验身份证校验类
 **/
public class IdcardValidtor implements ConstraintValidator<Idcard,String> {

    String regexp;

    @Override
    public void initialize(Idcard constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if(value==null){
            return true;
        }
        if( value.matches(regexp)){
            return true;
        }
        return false;
    }


}
